/**
 * 
 */
package com.lehecai.core.message.recharge;

import com.lehecai.core.util.CoreJSONUtils;
import net.sf.json.JSONObject;

/**
 * 大额充值报警消息对象
 * @author qatang
 *
 */
public class LargeRechargeAlarmMessage {

    private static final String JSON_KEY_RECHARGE_ID = "recharge_id";
	
	private static final String JSON_KEY_USERNAME = "username";
	
	private static final String JSON_KEY_AMOUNT = "amount";

	private static final String JSON_KEY_RECHARGE_TYPE = "type_name";

    private String rechargeId;

	private String rechargeType;

	private String username;
	
	private String amount;

	@Override
	public String toString() {
		JSONObject object = new JSONObject();

        object.put(JSON_KEY_RECHARGE_ID, rechargeId);
		object.put(JSON_KEY_USERNAME, username);
		object.put(JSON_KEY_AMOUNT, amount);
		object.put(JSON_KEY_RECHARGE_TYPE, rechargeType);

		return object.toString();
	}
	
	public static LargeRechargeAlarmMessage convertFromJSONString(String jsonString) {
		try {
			return convertFromJSONObject(JSONObject.fromObject(jsonString));
		} catch (Exception e) {
			return null;
		}
	}
	
	/**
	 * 每个字段不能为空，否则转换失败
	 * @param jsonObject
	 * @return 转换失败返回null
	 */
	public static LargeRechargeAlarmMessage convertFromJSONObject(JSONObject jsonObject) {
		LargeRechargeAlarmMessage message = new LargeRechargeAlarmMessage();
		try {
            message.setRechargeId(CoreJSONUtils.getString(jsonObject, JSON_KEY_RECHARGE_ID));
            message.setUsername(CoreJSONUtils.getString(jsonObject, JSON_KEY_USERNAME));
            message.setAmount(CoreJSONUtils.getString(jsonObject, JSON_KEY_AMOUNT));
            message.setRechargeType(CoreJSONUtils.getString(jsonObject, JSON_KEY_RECHARGE_TYPE));
		} catch (Exception e) {
			return null;
		}
		return message;
	}

    public String getRechargeId() {
        return rechargeId;
    }

    public void setRechargeId(String rechargeId) {
        this.rechargeId = rechargeId;
    }

    public String getRechargeType() {
        return rechargeType;
    }

    public void setRechargeType(String rechargeType) {
        this.rechargeType = rechargeType;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }
}
